home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program performs a nine-point smoothing, where each point is updated
- * to be the average of his eight neighbors. The matrix is M x N, where
- * M is a multiple of P1, and N is a multiple of P2. The use of asynchronous
- * variables is demonstrated here. */
-
- #include "dino.h"
-
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x < y ? x : y)
-
- #define M 12
- #define N 8
- #define P1 4
- #define P2 4
-
- environment node[P1:id1][P2:id2] {
-
- composite smooth (a, in iter)
- double /*asynch*/ distributed a[M][N] map NinePt;
-
- /* ==> The NinePt mapping is just like FivePt,
- except that the four corner overlap
- elements are included in the overlap. */
-
- /* ==> Note the use of the "asynch" keyword,
- making communications using the matrix a
- non-blocking. This program will run
- either synchronous or asynchronous. */
-
- int iter;
-
- {
- int i, j, k; /* Looping variables */
-
- int home_n, home_s, home_w, home_e; /* Boundaries of the home data */
- int copy_n, copy_s, copy_w, copy_e; /* Boundaries of the copy data */
-
- /* Compute home_n, home_s, home_w, and home_e */
- home_n = max (M/P1 * id1, 1);
- home_s = min ((id1 + 1) * M/P1 - 1, M-2);
- home_w = max (N/P2 * id2, 1);
- home_e = min ((id2 + 1) * N/P2 - 1, N-2);
-
- /* Compute copy_n, copy_s, copy_w, and copy_e */
- copy_n = max (home_n - 1, 1);
- copy_s = min (home_s + 1, M-2);
- copy_w = max (home_w - 1, 1);
- copy_e = min (home_e + 1, N-2);
-
- /* Repeat the smoothing process iter times */
- for (i = 0; i < iter; i++) {
-
- /* Send out your data and receive it back again, if not the first
- * iteration */
- if (i != 0) {
- a[<home_n,home_s>][<home_w,home_e>]# =
- a[<home_n,home_s>][<home_w,home_e>];
- a[<copy_n,copy_s>][<copy_w,copy_e>]#;
- }
-
- /* Perform the computation, but only on non-edge elements */
- for (j = home_n; j <= home_s; j++)
- for (k = home_w; k <= home_e; k++) {
- a[j][k] = a[j-1][k-1] +
- a[j-1][k] +
- a[j-1][k+1] +
- a[j][k-1];
-
- /* ==> The computation has been split up into
- three separate pieces because some
- compiler's can't handle the large
- expression produced by DINO. */
-
- a[j][k] += a[j][k+1] +
- a[j+1][k-1] +
- a[j+1][k] +
- a[j+1][k+1];
-
- a[j][k] /= 8;
-
- }
- }
- }
- }
-
- environment host {
-
- void main ()
-
- {
- double a[M][N]; /* Input data */
- int iter; /* Holds the iteration count */
-
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] */
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = (i + 1)*(j + 1);
- for (i = 1; i < M - 1; i++)
- for (j = 1; j < N - 1; j++)
- a[i][j] = 0;
-
- /* Set up the variable which will contain the number of iterations */
- iter = 300;
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%7.2f", a[i][j]);
- printf ("\n");
- }
-
- /* Perform the computation */
- smooth (a[][], iter)#;
-
- /* Printout the results */
- printf ("Result data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%7.2f", a[i][j]);
- printf ("\n");
- }
- }
- }
-
-